import cgi

from google.appengine.api import users           # google's user authentication (OpenID etc.)
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

import auth

#
# Request handlers
#

class CreateAccountPage(webapp.RequestHandler):
    def get(self):
        if  users.get_current_user():
            # verify user doesn't already exist
            found = False
            query=auth.User.all()
            query.filter('userid =', users.get_current_user())
            for q in query:
                found = True
                break
            
            if not found:
                # create current user as new user
                account = auth.User(userid=users.get_current_user())
                account.put()

        self.redirect('/')

#
# Url switching table
#

application = webapp.WSGIApplication([
        ('/create_account', CreateAccountPage),
        ], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()


